const launch = require('../runner/index');
const automator = require('miniprogram-automator');

const watchApp = function (ipcMain) {
	let miniProgram;
	let page;
	ipcMain.on('launch-app', function (event, filePath) {
		// filePath是从渲染进程返回来的数据
		console.log("【ipcMain】收到消息：", filePath);

		automator.launch({
			projectPath: '/Users/junyitan/Desktop/doctorwork/iPenguinDoctor_qa/dist',
		}).then(res => {
			miniProgram = res;
			miniProgram.reLaunch(
				'/packages/doctorwork/pages/searchResult/index',
			).then(res => {
				page = res;
			})
		})

	})

	ipcMain.on('fill-input', function (event, content) {
		console.log(page)
		// filePath是从渲染进程返回来的数据
		console.log("【ipcMain】收到消息：", content);
		page.$('search-box').then(searchBox => {
			searchBox.$('.searchInput').then(input => {
				input.input(content)
			})
		})
	})

	ipcMain.on('btn-click', function (event, filePath) {
		// filePath是从渲染进程返回来的数据
		console.log(page)
		console.log("【ipcMain】收到消息：", filePath);
		page.$('search-box').then(searchBox => {

			searchBox.$('.searchButton').then(button => {
				button.tap()
			})
		})
	})
}

module.exports = watchApp;